<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition xmlns:ui="http://java.sun.com/jsf/facelets"
                template="/resources/template/template.xhtml"
                xmlns:h="http://java.sun.com/jsf/html"
                xmlns:f="http://java.sun.com/jsf/core"
                xmlns="http://www.w3.org/1999/xhtml"
                xmlns:p="http://primefaces.org/ui"
                xmlns:in="http://java.sun.com/jsf/composite/inward">
    <ui:define name="content">
        <h:panelGroup >
            <h:form  >
                <p:panel >
                    <f:facet name="header" >
                        <h:panelGrid columns="10"  >
                            <h:outputLabel value="Inward Timed Service" />
                            <p:commandButton ajax="false" value="Clear" action="#{inwardTimedItemController.makeNull}" onclick="onSubmitButton();"  />
                            
                        </h:panelGrid>
                    </f:facet>    
                    <h:panelGrid columns="2">
                        <p:panel header="Patient Details">
                            <h:outputLabel value="Type Surgery Name or BHT : "/>
                            <p:autoComplete forceSelection="true" 
                                            value="#{inwardTimedItemController.batchBill}" 
                                            completeMethod="#{billController.completeSurgeryBills}"
                                            var="apt2" itemLabel="#{amp2.bhtNo}"
                                            itemValue="#{apt2}" size="30"  style="width: 400px;">
                                <p:ajax event="itemSelect" process="@this" update="panSearch1 panSearch2"
                                        listener="#{inwardTimedItemController.selectSurgeryBillListener()}"/>
                                <p:column headerText="Surgery Name">
                                    <h:outputLabel value="#{apt2.procedure.item.name}"/> 
                                </p:column>
                                <p:column headerText="BHT NO">
                                    <h:outputLabel value="#{apt2.patientEncounter.bhtNo}"/> 
                                </p:column>
                                <p:column headerText="Patient Name" >
                                    <h:outputLabel value="#{apt2.patientEncounter.patient.person.name}">                                                
                                    </h:outputLabel>
                                </p:column>
                            </p:autoComplete>  

                            <br/>
                            <h:panelGroup id="panSearch1">
                                <in:bhtDetail admission="#{inwardTimedItemController.batchBill.patientEncounter}"/>
                            </h:panelGroup>    <br/>                                
                            <h:panelGroup id="panSearch2">
                                <in:surgeryDetail procedure="#{inwardTimedItemController.batchBill.procedure}"/>
                            </h:panelGroup>
                        </p:panel>


                        <p:panel header="Timed Item">
                            <h:panelGrid columns="2">
                                <h:outputLabel value="Timed Item"/>
                                <p:autoComplete  forceSelection="false" 
                                                 value="#{inwardTimedItemController.timedEncounterComponent.billFee.patientItem.item}"
                                                 completeMethod="#{timedItemController.completeInvest}" var="ix" 
                                                 itemLabel="#{ix.name}" itemValue="#{ix}" size="30"  style="width: 400px;">                              
                                    <p:column>
                                        #{ix.name}
                                    </p:column>
                                    <p:column>
                                        #{ix.total}
                                    </p:column>
                                </p:autoComplete>

                                <p:outputLabel value="StartTime:"/>
                                <p:calendar id="startTime"  value="#{inwardTimedItemController.timedEncounterComponent.billFee.patientItem.fromTime}" 
                                            pattern="dd MMMM yyyy hh mm ss a" >                             
                                </p:calendar>                                                                      


                                <p:commandButton value="Add Time Service" ajax="false"
                                                action="#{inwardTimedItemController.addTimedService()}"
                                                 disabled="#{inwardTimedItemController.batchBill.patientEncounter.paymentFinalized}" onclick="onSubmitButton();" />



                            </h:panelGrid>   

                        </p:panel> 

                    </h:panelGrid> 
                    <p:panel header="Consumed Timed Sevice" id="con">                          
                        <p:dataTable value="#{inwardTimedItemController.timedEncounterComponents}" var="ti">
                            <p:column headerText="Service Name">
                                #{ti.billFee.patientItem.item.name}
                            </p:column>
                            <p:column headerText="Start Time">
                                <p:calendar navigator="true"  
                                            value="#{ti.billFee.patientItem.fromTime}" 
                                            pattern="dd MMMM yyyy hh mm ss a" />                                      
                            </p:column>                               
                            <p:column headerText="Stopped Time">
                                <p:calendar navigator="true"  
                                            value="#{ti.billFee.patientItem.toTime}" 
                                            pattern="dd MMMM yyyy hh mm ss a" />  
                            </p:column>
                            <p:column headerText="Total">
                                #{ti.billFee.patientItem.serviceValue}
                            </p:column>
                            <p:column >
                                <h:outputLabel value="#{ti.billFee.createdAt}">
                                    <f:convertDateTime pattern="dd MM yyyy"/>
                                </h:outputLabel>                                                   
                                <br/>
                                <h:panelGroup rendered="#{ti.billFee.retired}" >
                                    <h:outputLabel style="color: red;" value="Deleted at " />
                                    <h:outputLabel style="color: red;"  value="#{ti.billFee.retiredAt}" >
                                        <f:convertDateTime pattern="dd MMM yyyy"/>
                                    </h:outputLabel>
                                </h:panelGroup>
                            </p:column>
                            <p:column >
                                <h:outputLabel value="#{ti.billFee.creater.webUserPerson.name}"/>     
                                <br/>
                                <h:panelGroup rendered="#{ti.billFee.retired}" >
                                    <h:outputLabel style="color: red;" value="Deleted By " />
                                    <h:outputLabel style="color: red;"  value="#{ti.billFee.retirer.webUserPerson.name}" >                                       
                                    </h:outputLabel>
                                </h:panelGroup>
                            </p:column>     
                            <p:column >
                                <p:commandButton value="Update" ajax="false"  
                                                action="#{inwardTimedItemController.updateTimedService(ti.billFee)}"
                                                 disabled="#{ti.billFee.id eq null or inwardTimedItemController.batchBill.patientEncounter.paymentFinalized}" onclick="onSubmitButton();" />                                                                    
                            </p:column>
                            <p:column headerText="Remove">
                                <p:commandButton ajax="false" value="Remove"  
                                                 rendered="#{ti.billFee.id eq null}"
                                                action="#{inwardTimedItemController.removeTimedEncFromList(ti)}"
                                                 disabled="#{inwardTimedItemController.batchBill.patientEncounter.paymentFinalized}" onclick="onSubmitButton();" />
                                <p:commandButton ajax="false" value="Remove "  
                                                 rendered="#{ti.billFee.id ne null}"
                                                action="#{inwardTimedItemController.removeTimedEncFromDbase(ti)}"
                                                 disabled="#{inwardTimedItemController.batchBill.patientEncounter.paymentFinalized}" onclick="onSubmitButton();" />
                            </p:column>
                        </p:dataTable>
                    </p:panel>



                </p:panel>
            </h:form>

        </h:panelGroup>

    </ui:define>

</ui:composition>
